package homework04.test01;

public class Worker {
    /**
     * 用户姓名
     */
    private String name;
    /**
     * 用户年龄
     */
    private int age;

    public Worker(String name, int age) throws AgeException, EmptyException {
        setName(name);
        setAge(age);
    }

    public Worker() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) throws EmptyException {
        if (null == name || "".equals(name)) {
            throw new EmptyException("姓名不能为空哦!!!");
        }
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws AgeException {
        if (age < 18 || age > 150) {
            throw new AgeException("年龄不合理哦!!!");
        }
        this.age = age;
    }

    @Override
    public String toString() {
        return "Worker{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
